import { defineStore } from "pinia"
import {findAllUser} from "@/apis/UserApi"

export const userStore = defineStore("userStore", {
    //尽量定义一个函数，返回仓库的数据
    state: () => {
        return {
            count: 10,
            user: []
        }
    },
    //计算属性，每一个定义都是依赖于state的数据
    getters: {
        doubleCount(state) {
            return state.count * 2
        }
    },
    //存放函数，同步和异步都放在这个函数中
    actions: {
        increment(val: number) {
            this.count += val
        },
        decrement(val: number) {
            this.count -= val
        },
        async asyncFindUser(){
            const res =  await findAllUser()
            console.log(res);
            this.user = res.data.data
        }
    }
})